package gw.com.android.ui.quote2.view;

import android.content.Context;
import android.support.v4.app.FragmentActivity;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.LinearLayout;

import com.gwtsz.gts2.hx.R;

import gw.com.android.app.AppContances;
import gw.com.android.model.ConfigSettingDeal;
import gw.com.android.terminal.AppTerminal;
import gw.com.android.utils.PackStatis;
import www.com.library.util.CommonUtils;
import www.com.library.util.NetworkMonitor;
import www.com.library.view.TintImageTextView;
import www.com.library.view.TintTextView;

/**
 * 服务器连接失败ui
 * @author reeta.zou
 *
 */
public class ServerErrorView extends LinearLayout implements OnClickListener {

	private TintImageTextView mImageView;
	private TintTextView mCustomView;
	private FragmentActivity cxt;

	public ServerErrorView(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		init(context);
	}

	public ServerErrorView(Context context, AttributeSet attrs) {
		super(context, attrs);
		init(context);
	}

	public ServerErrorView(Context context) {
		super(context);
		init(context);
	}

	/**
	 * 初始化控件信息
	 * @param ctx
	 */
	private void init(Context ctx) {
		setOrientation(LinearLayout.HORIZONTAL);
		cxt = (FragmentActivity) ctx;
		View view = LayoutInflater.from(ctx).inflate(R.layout.view_common_server_error, this, true);
		mImageView = (TintImageTextView) view.findViewById(R.id.severerror_icon);
		view.findViewById(R.id.error_layout).setOnClickListener(this);

		mCustomView = (TintTextView) view.findViewById(R.id.custom_click);
		mCustomView.setOnClickListener(this);

	}

	@Override
	public void onClick(View v) {
		if (CommonUtils.isFastDoubleClick())
			return;

		if (v.getId() == R.id.custom_click) {
			// 在线客服
			ConfigSettingDeal mDeal = new ConfigSettingDeal();
			mDeal.openQQ(cxt);
			PackStatis.getToService(PackStatis.EventAction.CLICKSERVICE.getValue(), PackStatis.EventCategory.MARKET.getValue(),null,null);
		} else if (v.getId() == R.id.error_layout) {
			if(NetworkMonitor.hasNetWork()){
				AppTerminal.instance().setReConnect(AppContances.SERVER_TYPE_BOTH);
			}
		}
	}
}